package pers.archives.home.util;

import pers.archives.common.entity.Menu;
import pers.archives.common.ov.OVMenus;

import java.util.ArrayList;
import java.util.List;

/*
 *@program:archives-parent
 *@author: 赵浩浩
 *@Time: 2020/9/19  17:12
 */
public class MenuUtils {

    /**
     * 拼接菜单
     * @param menu 父集菜单
     * @param menus 需要拼接的菜单集合
     * @return
     */
    public static List<OVMenus> splicingMenu(Menu menu, List<Menu> menus) {
        List<OVMenus> ovs = new ArrayList<>();
        menus.forEach(m -> {
            if(menu.getId().equals(m.getParent_id())) {
                List<OVMenus> menus1 = splicingMenu(m, menus);
                OVMenus ov = new OVMenus().add(m);
                ov.setChildren(menus1);
                ovs.add(ov);
            }
        });
        return ovs;
    }


}
